//
//  AXMySrdzWdjsSchemeDetailsVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/8.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXMySrdzWdjsSchemeDetailsVC.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "Header.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "UIViewController+HBD.h"
#import "AXMySrdzWdjsSchemeDetailsVC.h"

#import "AXMyWdjsSchemeDetailsFirstCell.h"
#import "AXMyWdjsSchemeDetailsSecondCell.h"
#import "AXMyWdjsSchemeDetailsThirdCell.h"
#import "AXMyWdjsSchemeDetailsFourCell.h"
#import "AXMyWdjsSchemeDetailsFiveCell.h"
#import "AXMyWdjsSchemeDetailsSixCell.h"
#import "AXMyWdjsSchemeDetailsSevenCell.h"
#import "AXMyWdjsSchemeDetailsEightCell.h"
#import "AXMyWdjsSchemeDetailModel.h"
#import "AXMyWdjsSchemeDetailsNineCell.h"
#import "MBProgressHUD.h"



@interface AXMySrdzWdjsSchemeDetailsVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) AXMyWdjsSchemeDetailModel *scheneDetail;
@property (nonatomic, strong) NSMutableArray<DiseaseMedicineModel *>  *modelsArray1;
@property (nonatomic, strong) NSMutableArray<DiseaseFertilizerModel *>  *modelsArray2;
@property (nonatomic, strong) NSMutableArray<InsectMedicineModel *>  *modelsArray3;
@property (nonatomic, strong) NSMutableArray<GrassDamageMedicineModel *>  *modelsArray4;
@property (nonatomic, strong) NSMutableArray<DeficiencyFertilizerModel *>  *modelsArray5;
@property (nonatomic, strong) MBProgressHUD *hud;


@property (nonatomic ,strong) UITableView *tableView;

@end

@implementation AXMySrdzWdjsSchemeDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    [self requestDetailStrategyById];
    
}

- (void)creatView {
    
    self.tableView = [[UITableView alloc]init];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    
    [self.tableView registerClass:[AXMyWdjsSchemeDetailsSecondCell class] forCellReuseIdentifier:[AXMyWdjsSchemeDetailsSecondCell reuseID]];
    [self.tableView registerClass:[AXMyWdjsSchemeDetailsThirdCell class] forCellReuseIdentifier:[AXMyWdjsSchemeDetailsThirdCell reuseID]];
    [self.tableView registerClass:[AXMyWdjsSchemeDetailsFourCell class] forCellReuseIdentifier:[AXMyWdjsSchemeDetailsFourCell reuseID]];
    [self.tableView registerClass:[AXMyWdjsSchemeDetailsFiveCell class] forCellReuseIdentifier:[AXMyWdjsSchemeDetailsFiveCell reuseID]];
    [self.tableView registerClass:[AXMyWdjsSchemeDetailsSixCell class] forCellReuseIdentifier:[AXMyWdjsSchemeDetailsSixCell reuseID]];
    [self.tableView registerClass:[AXMyWdjsSchemeDetailsNineCell class] forCellReuseIdentifier:[AXMyWdjsSchemeDetailsNineCell reuseID]];
    [self.tableView registerClass:[AXMyWdjsSchemeDetailsSevenCell class] forCellReuseIdentifier:[AXMyWdjsSchemeDetailsSevenCell reuseID]];
    [self.tableView registerClass:[AXMyWdjsSchemeDetailsEightCell class] forCellReuseIdentifier:[AXMyWdjsSchemeDetailsEightCell reuseID]];
    [self.view addSubview:self.tableView];
    
    self.hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    
}


- (void)setlayout {
    
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, NAVIGATION_HEIGHT)
    .widthIs(Wi)
    .heightIs(TableViewHeight);
    
    
}

- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    /** title */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"方案详情";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)search:(UIButton *)btn {
    
}



#pragma mark - tableViewDelegate & tableViewDatasorce



//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 8;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        case 1:
            return 1;
            break;
        case 2:
            return [self.modelsArray1 count ];
            break;
        case 3:
            return  [self.modelsArray2 count];
            break;
        case 4:
            return [self.modelsArray3 count];
            break;
        case 5:
            return [self.modelsArray4 count];
            break;
        case 6:
            return [self.modelsArray5 count];
            break;
        default:
            break;
    }
    return 1;
}

/** cell的高度 */


/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.section) {
            
            /**  case 0:{
             return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray1[indexPath.row] keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsFirstCell class] contentViewWidth:SCREEN_WIDTH];
             break;
             }*/
        case 0:{
            
            return [tableView cellHeightForIndexPath:indexPath model:self.scheneDetail keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsSecondCell class] contentViewWidth:SCREEN_WIDTH];
            break;
            
        }
        case 1:{
            
            return [tableView cellHeightForIndexPath:indexPath model:self.scheneDetail keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsThirdCell class] contentViewWidth:SCREEN_WIDTH];
            break;
            
        }
        case 2:{
            
            return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray1[indexPath.row] keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsFourCell class] contentViewWidth:SCREEN_WIDTH];
            break;
            
        }
        case 3:{
            
            return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray2[indexPath.row] keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsFiveCell class] contentViewWidth:SCREEN_WIDTH];
            break;
            
        }
        case 4:{
            
            return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray3[indexPath.row] keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsSixCell class] contentViewWidth:SCREEN_WIDTH];
            break;
            
        }
        case 5:
            return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray4[indexPath.row] keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsNineCell class] contentViewWidth:SCREEN_WIDTH];
            
            
            
        case 6:{
            
            return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray5[indexPath.row] keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsSevenCell class] contentViewWidth:SCREEN_WIDTH];
            
            break;
        }
            
            
        default:
            break;
    }
    return [tableView cellHeightForIndexPath:indexPath model:self.scheneDetail keyPath:@"model" cellClass:[AXMyWdjsSchemeDetailsEightCell class] contentViewWidth:SCREEN_WIDTH];
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    switch (indexPath.section) {
            /***
             case 0:{
             AXMyWdjsSchemeDetailsFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsFirstCell reuseID] forIndexPath:indexPath];
             [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
             cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
             
             cell.bgView.sd_layout
             .leftSpaceToView(cell.contentView, 10)
             .topSpaceToView(cell.contentView, 10)
             .widthIs(SCREEN_WIDTH-20)
             .heightIs(190);
             return cell;
             break;
             }
             */
        case 0:{
            
            AXMyWdjsSchemeDetailsSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsSecondCell reuseID] forIndexPath:indexPath];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
            cell.model = self.scheneDetail;
            return cell;
            break;
            
        }
        case 1:{
            AXMyWdjsSchemeDetailsThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsThirdCell reuseID] forIndexPath:indexPath];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
            cell.model=self.scheneDetail;
            return cell;
            break;
            
        }
            
        case 2:{
            AXMyWdjsSchemeDetailsFourCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsFourCell reuseID] forIndexPath:indexPath];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
            cell.model=self.modelsArray1[indexPath.row];
            return cell;
            break;
            
        }
        case 3:{
            AXMyWdjsSchemeDetailsFiveCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsFiveCell reuseID] forIndexPath:indexPath];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
            cell.model=self.modelsArray2[indexPath.row];
            return cell;
            break;
        }
        case 4:{
            AXMyWdjsSchemeDetailsSixCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsSixCell reuseID] forIndexPath:indexPath];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
            cell.model=self.modelsArray3[indexPath.row];
            return cell;
            break;
            
        }
        case 5:{
            AXMyWdjsSchemeDetailsNineCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsNineCell reuseID] forIndexPath:indexPath];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
            cell.model=self.modelsArray4[indexPath.row];
            return cell;
            break;
        }
            
        case 6:{
            AXMyWdjsSchemeDetailsSevenCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsSevenCell reuseID] forIndexPath:indexPath];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
            cell.model=self.modelsArray5[indexPath.row];
            return cell;
            break;
        }
        default:
            break;
    }
    
    AXMyWdjsSchemeDetailsEightCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyWdjsSchemeDetailsEightCell reuseID] forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
    cell.model=self.scheneDetail;
    return cell;
    
    
}
/**获取方案详情**/
-(void)requestDetailStrategyById{
    
    ZX_WEAK_SELF
    
    NSMutableDictionary *param=[NSMutableDictionary dictionary];
    param[@"strategyId"]=self.strategyId;
    
    [ NetWorkHelp yl_postDataWith:param url:URL_SPLIT(URL_AgricultureCircleProfessorDiagnose,URL_AgricultureCircleProfessorDiagnose_StrategyById) success:^(id respose) {
        [self.hud hideAnimated:YES];
        if([respose[@"header"][@"statusCode"] integerValue]==200){
            weakSelf.scheneDetail=[AXMyWdjsSchemeDetailModel mj_objectWithKeyValues:respose[@"body"][@"data"]];
            weakSelf.modelsArray1=[DiseaseMedicineModel mj_objectArrayWithKeyValuesArray:respose[@"body"][@"data"][@"map"][@"fDiseaseMedicine"]];
            weakSelf.modelsArray2=[DiseaseFertilizerModel mj_objectArrayWithKeyValuesArray:respose[@"body"][@"data"][@"map"][@"fDiseaseFertilizer"]];
            weakSelf.modelsArray3=[InsectMedicineModel mj_objectArrayWithKeyValuesArray:respose[@"body"][@"data"][@"map"][@"fInsectMedicine"]];
            weakSelf.modelsArray4=[GrassDamageMedicineModel mj_objectArrayWithKeyValuesArray:respose[@"body"][@"data"][@"map"][@"fGrassDamageMedicine"]];
            weakSelf.modelsArray5=[DeficiencyFertilizerModel mj_objectArrayWithKeyValuesArray:respose[@"body"][@"data"][@"map"][@"fDeficiencyFertilizer"]];
            [self.tableView reloadData];
        }
        
    } failure:^(NSError *error) {
        [self.hud hideAnimated:YES];
    }];
}



- (NSMutableArray<DiseaseMedicineModel *> *) modelsArray1{
    
    if (!_modelsArray1) {
        
        _modelsArray1 = [NSMutableArray<DiseaseMedicineModel *> array];
    }
    return _modelsArray1;
    
}

- (NSMutableArray<DiseaseFertilizerModel *> *) modelsArray2{
    
    if (!_modelsArray2) {
        
        _modelsArray2 = [NSMutableArray<DiseaseFertilizerModel *> array];
    }
    return _modelsArray2;
    
}


- (NSMutableArray<InsectMedicineModel *> *) modelsArray3{
    
    if (!_modelsArray3) {
        
        _modelsArray3 = [NSMutableArray<InsectMedicineModel *> array];
    }
    return _modelsArray3;
    
}

- (NSMutableArray<GrassDamageMedicineModel *> *) modelsArray4{
    
    if (!_modelsArray4) {
        
        _modelsArray4 = [NSMutableArray<GrassDamageMedicineModel *> array];
    }
    return _modelsArray4;
    
}

- (NSMutableArray<DeficiencyFertilizerModel *> *) modelsArray5{
    
    if (!_modelsArray5) {
        
        _modelsArray5= [NSMutableArray<DeficiencyFertilizerModel *> array];
    }
    return _modelsArray5;
    
}


@end


